#include <stdio.h>
#include <winsock2.h> 
#include <winsock.h> 
#pragma comment(lib,"ws2_32.lib")
#define BUF_SIZE 100
int main() {
	SOCKET slisten;
	SOCKET connectionSocket;
	struct sockaddr_in servAddr;
	struct sockaddr_in clntAddr;
	int nAddrlen;
	int strLen;
	char revData[BUF_SIZE];
	WSADATA wsaData;
	WSAStartup(MAKEWORD(2, 2), &wsaData);
	slisten = socket(AF_INET, SOCK_STREAM, 0);
	servAddr.sin_family = AF_INET;
	servAddr.sin_port = htons(8888);
	servAddr.sin_addr.s_addr = INADDR_ANY;
	bind(slisten, (struct sockaddr*)&servAddr, sizeof(servAddr));
	listen(socket, 5);
	nAddrlen = sizeof(clntAddr);
	while (1) {
		connectionSocket = accept(slisten, (struct sockaddr*)&clntAddr, &nAddrlen);
		strLen = recv(connectionSocket, revData, BUF_SIZE, 0);
		send(connectionSocket, revData, strlen, 0);
		closesocket(connectionSocket);
	}
	closesocket(slisten);
	WSACleanup();
	return 0;
}
//#include <stdio.h> 
//#include <string.h> 
//#define _WINSOCK_DEPRECATED_NO_WARNINGS 1
//#include <winsock2.h> 
//#pragma comment(lib,"ws2_32.lib")
//#define BUF_SIZE 100
//#define _WINSOCK_DEPRECATED_NO_WARNINGS 1
//
//
//int main() {
//	SOCKET clientSocket;
//	struct sockaddr_in serAddr;
//	char buffer[BUF_SIZE];
//	int strLen;
//	WSADATA wsaData;
//	WSAStartup(MAKEWORD(2, 2), &wsaData);
	//clientSocket = socket(AF_INET, SOCK_STREAM, 0);
	//serAddr.sin_family = AF_INET;
	//serAddr.sin_port = htons(1234);
	//serAddr.sin_addr.s_addr = inet_addr("172.20.10.2");
	//int ret=connect(clientSocket, (struct sockaddr*)&serAddr, sizeof(serAddr));
	//printf("%d\n", ret);
//
//	while (1) {
//		printf("Input a string: ");
//		gets(buffer);
//		send(clientSocket, buffer, strlen(buffer), 0);
//		strLen = recv(clientSocket, buffer, BUF_SIZE, 0);
//		printf("%d\n", strLen);
//		if(strlen<100)
//		buffer[strLen] = 0;
//		printf("Message forn server: %s\n", buffer);
//	}
//	closesocket(clientSocket);
//	WSACleanup();
//	return 0;
//}
